<?php
function lib_projecttype(&$ctag,&$refObj)
{
    global $dsql,$envs;
    //属性处理
    $attlist="row|5,id|0,titlelen|";
    FillAttsDefault($ctag->CAttribute->Items,$attlist);
    extract($ctag->CAttribute->Items, EXTR_SKIP);
 
    $innertext = trim($ctag->GetInnerText());
    if(empty($innertext)) $innertext ="[field:title/]";
    if(empty($row)) $row=5;
    if(empty($titlelen)) $titlelen=30;
    $idsql = '';
    if(!empty($id))
    {
     $idsql = " WHERE id='{$id}'";
     }
    $dsql->SetQuery("SELECT * FROM #@__projecttype $idsql ORDER BY id ASC LIMIT 0,$row");
    $dsql->Execute();
    $ctp = new DedeTagParse();
    $ctp->SetNameSpace('field','[',']');
    $ctp->LoadSource($innertext);
    $revalue = '';
    $GLOBALS['autoindex'] = 0;

    while($row = $dsql->GetArray())
    {
       
        $GLOBALS['autoindex']++;
        foreach($ctp->CTags as $tagid=>$ctag){
            @$ctp->Assign($tagid,$row[$ctag->GetName()]);
        }
        $revalue .= $ctp->GetResult();
    }
    return $revalue;
}